import '../yaml/visit.js';
import '../yaml/stringify/stringifyString.js';
import '../yaml/parse/cst-visit.js';
import { parse as f } from '../yaml/public-api.js';
let i = '\\ufeff?',
  p = typeof process < 'u' ? process.platform : '',
  u =
    '^(' +
    i +
    '(= yaml =|---)$([\\s\\S]*?)^(?:\\2|\\.\\.\\.)\\s*$' +
    (p === 'win32' ? '\\r?' : '') +
    '(?:\\n)?)',
  o = new RegExp(u, 'm');
function x(e, t) {
  e = e || '';
  let r = {};
  t = t instanceof Object ? { ...r, ...t } : r;
  let l = e.split(/(\r?\n)/);
  return l[0] && /= yaml =|---/.test(l[0])
    ? c(e)
    : {
        attributes: {},
        body: e,
        bodyBegin: 1,
      };
}
function s(e, t) {
  let r = 1,
    l = t.indexOf(`
`),
    n = e.index + e[0].length;
  for (; l !== -1; ) {
    if (l >= n) return r;
    r++,
      (l = t.indexOf(
        `
`,
        l + 1,
      ));
  }
  return r;
}
function c(e) {
  let t = o.exec(e);
  if (!t)
    return {
      attributes: {},
      body: e,
      bodyBegin: 1,
    };
  let r = t[t.length - 1].replace(/^\s+|\s+$/g, ''),
    l = f(r) || {},
    n = e.replace(t[0], ''),
    a = s(t, e);
  return {
    attributes: l,
    body: n,
    bodyBegin: a,
    frontmatter: r,
  };
}
function O(e) {
  return (e = e || ''), o.test(e);
}
export { x as default, c as parse, O as test };
